package vn.cuhanh.fragment;

import vn.cuhanh.BaseActivity;
import vn.cuhanh.ChooseGameActivity;
import vn.cuhanh.GameDetailActivity;
import vn.cuhanh.R;
import vn.cuhanh.utils.HelperFunc;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.InflateException;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;

public class HelpFragment extends BasicFragment {
	
	private View view;
	
	public static HelpFragment newInstance(Context ctx) {
		return new HelpFragment(ctx);
	}

	public HelpFragment(Context ctx) {
		super(ctx);
	}

	public HelpFragment() {
		super(GameDetailActivity.gameDetailContext);
	}

	@Override
	public void onSaveInstanceState(Bundle outState) {
		super.onSaveInstanceState(outState);
	}

	@Override
	public void onPause() {
		super.onPause();
		// HelperFunc.unbindDrawables(view);
		// System.gc();
	}

	@Override
	public void onDestroy() {
		super.onDestroy();
	}
	
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		try {
			view = inflater.inflate(R.layout.help_fragment, null);
			if (ctx == null || view == null) {
				if (isAdded()) {
					ctx = getActivity();
				} else {
					return view;
				}
			}
			View btnCallHelp = view.findViewById(R.id.btn_call_helper);
			btnCallHelp.setOnClickListener(new OnClickListener() {
				@Override
				public void onClick(View v) {
					// TODO Auto-generated method stub
					HelperFunc.trackEvent(ctx, "help_fragment", "btn_call_press", "btn_call_press");
					Intent callIntent = new Intent(Intent.ACTION_CALL);
					callIntent.setData(Uri.parse("tel:" + ctx.getResources().getInteger(R.integer.help_hot_line_no)));
					startActivity(callIntent);
				}
			});
//			View btnEmailHelp = view.findViewById(R.id.btn_email_helper);
//			btnEmailHelp.setOnClickListener(new OnClickListener() {
//				
//				@Override
//				public void onClick(View v) {
//					// TODO Auto-generated method stub
//					Intent email = new Intent(Intent.ACTION_SEND);
//					email.putExtra(Intent.EXTRA_EMAIL, ctx.getResources().getStringArray(R.array.help_email_addresses));          
//					email.putExtra(Intent.EXTRA_SUBJECT, ctx.getResources().getString(R.string.help_email_subject));
//					email.putExtra(Intent.EXTRA_TEXT, ctx.getResources().getString(R.string.help_email_content));
//					email.setType("message/rfc822");
//					startActivity(Intent.createChooser(email, ctx.getResources().getString(R.string.help_email_create_chooser_message)));
//				}
//			});
			return view;
		} catch (InflateException e) {
			HelperFunc.readStackTrace(e);
		} catch (Exception e) {
			HelperFunc.readStackTrace(e);
		}
		return null;
	}
	
	@Override
	public void onResume() {
		super.onResume();
		View footer = view.findViewById(R.id.footer);
		BaseActivity.updateDndScore(footer);
	}
	
	@Override
	public void onActivityCreated(Bundle savedInstanceState) {
		super.onActivityCreated(savedInstanceState);
		setRetainInstance(true);
	}
}
